package com.qf.mvc.controller;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@RestControllerAdvice
public class MyRestExHandler {
    @ExceptionHandler(RuntimeException.class)
    public Map<String,String> exHandler(RuntimeException run){
        System.out.println(run);
        Map<String,String> map=new HashMap<>();
        map.put("msg",run.getMessage());
        map.put("lmsg",run.getLocalizedMessage());
        map.put("date",new Date().toString());
        return map;
    }
    @ExceptionHandler(Exception.class)
    public Map<String,String> exHandler(Exception ex){
        System.out.println(ex);
        Map<String,String> map=new HashMap<>();
        map.put("msg",ex.getMessage());
        map.put("lmsg",ex.getLocalizedMessage());
        map.put("date",new Date().toString());
        return map;
    }
}
